/**
 * desc: table demo component
 * author: Joe
 * date: 8/7/2018
 */

appModule.controller('TableDemoController',
  [
    '$rootScope', '$scope', '$document', 'api',
    function($rootScope, $scope, $document, api) {
      var tableSize = $rootScope.tableSize;

      var colData = [
        {
          key: 'name',
          text: '名称',
        },
        {
          key: 'info',
          text: '使用说明',
        },
        {
          key: 'url',
          text: 'url',
        },
        {
          key: 'createDate',
          text: '创建时间'
        },
        {
          key: 'lastDate',
          text: '最后修改时间'
        },
        {
          key: 'action',
          text: '操作',
          template: function() {
            return '<span class="plugin-action" gm-click="greeting">删除</span>';
          },
        },
      ];

      $scope.option = {
        gridManagerName: 'table-demo',
        columnData: colData,
        ajax_data: api.getLearnLinkList,
        query: {pluginId: 1},
      };

      $scope.greeting = function() {
        alert('hello, world!');
      };

      $scope.inputForm = [
        {
          key: 'city',
          title: 'City',
        }
      ];

      var states = ('AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS ' +
        'MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI ' +
        'WY').split(' ').map(function (state) { return { value: state, label: state }; });
      $scope.selectForm = [
        {
          key: 'state',
          title: 'State',
          option: states,
        }
      ];

      $scope.buttonForm = [
        {
          title: 'Searching'
        }
      ];

      $scope.buttonList = [
        {
          title: 'Batch Process',
          action: function() {
            console.log($document.find('table')[0].GM('getCheckedData'));
          }
        }
      ];

      $scope.action = function(formData) {
        $document.find('table')[0].GM('setQuery', formData);
      }
    }
  ]
);
